package com.example.musicwebcon.controller;

import com.example.musicwebcon.model.ResponseMessage;
import com.example.musicwebcon.model.dto.songDTO;
import com.example.musicwebcon.model.song;
import com.example.musicwebcon.service.serviceInterface.IsongService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/songs")
public class songController {
    @Autowired
    IsongService songService;
    @PostMapping
    public ResponseMessage add(@Validated @RequestBody songDTO song){
        song Song = songService.add(song);
        return ResponseMessage.success(Song);
    }
    @PostMapping("/all")
    public ResponseMessage addBatch(@Validated @RequestBody Iterable<songDTO> songs){
        Iterable<song> Songs = songService.addBatch(songs);
        return ResponseMessage.success(Songs);
    }
    @GetMapping("/{musicId}")
    public ResponseMessage getMusicId(@PathVariable String musicId){
        song Song = songService.getMusicId(musicId);
        return ResponseMessage.success(Song);
    }
    @GetMapping("/all/{songListId}")
    public ResponseMessage getAllBySongListId(@PathVariable String songListId){
        Iterable<song> songs = songService.getAllBysongListId(songListId);
        return ResponseMessage.success(songs);
    }
    @GetMapping("/userall/{userId}")
    public ResponseMessage getAlluserId(@PathVariable String userId){
        Iterable<song> songs = songService.getAllByuserId(userId);
        return ResponseMessage.success(songs);
    }
    @PutMapping()
    public ResponseMessage edit(@Validated @RequestBody songDTO song){
        song Song = songService.edit(song);
        return ResponseMessage.success(Song);
    }
    @DeleteMapping("/{musicId}")
    public ResponseMessage deleteBymusicId(@PathVariable String musicId){
        songService.deleteMusicId(musicId);
        return ResponseMessage.success(null);
    }
    @DeleteMapping("/all/{songListId}")
    public ResponseMessage deleteBysongListId(@PathVariable String songListId){
        songService.deleteSongListId(songListId);
        return ResponseMessage.success(null);
    }

}
